<?php
include("model/product_place.php");
class productplaceController{
	
	function indexAction(){
		$smarty = $_SESSION['smarty'];
		
		$list_productplace_box = $this->getListProductPlaceBox();
		$smarty->assign("list_productplace_box",$list_productplace_box);
		
		$content = $smarty->fetch("productplace/productplace.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function getListProductPlaceBox()
	{
		$smarty 			= $_SESSION['smarty'];
		$productplace_obj 	= new productplace();
		$productplaceList	= $productplace_obj->getProductPlaceList();		
		$smarty->assign("productplaceList", $productplaceList);
		$html 				= $smarty->fetch("productplace/productplace_list.html");
		return $html;
	}
	
	
	
	function activeAction(){
		$propla_id 			= $_REQUEST['args'];
		$productplace_obj 	= new productplace();
		$result 			= $productplace_obj->activateAProductPlace($propla_id);
		if ($result == 1)
			$msg = "activate successfully";		
		else
			$msg = "activate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		
		$list_productplace_box = $this->getListProductPlaceBox();
		$smarty->assign("list_productplace_box",$list_productplace_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("productplace/productplace.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	
	
	function inactiveAction(){
		$propla_id 			= $_REQUEST['args'];
		$productplace_obj	= new productplace();
		$result 			= $productplace_obj->inactivateAProductPlace($propla_id);
		if ($result == 1)
			$msg = "inactivate successfully";		
		else
			$msg = "inactivate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		
		$list_productplace_box = $this->getListProductPlaceBox();
		$smarty->assign("list_productplace_box",$list_productplace_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("productplace/productplace.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	function insertAction(){
		$productplace_obj 				= new productplace();
		$data 							= array();
		$data['propla_quantity'] 		= $_REQUEST['propla_quantity'];
		$data['propla_pro_id'] 			= $_REQUEST['propla_pro_id'];
		$data['propla_pla_id'] 			= $_REQUEST['propla_pla_id'];
		//$data['propla_type']			= $_REQUEST['propla_type'];
	
		$result = $productplace_obj->insertAProductPlace($data);
		if ($result == 1)
			$msg = "insert successfully";
		else if ($result == -1)
			$msg = "duplicated!";
		else
			$msg = "insert failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("productplace/productplace_insertResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
		
	}
	
	function insertFormAction(){
		$smarty = $_SESSION['smarty'];		
		
		$placesList = array();
		include("model/places.php");
		$places_obj = new places();
		$placesList = $places_obj->getPlaceList();
		
		$productsList = array();
		include("model/products.php");
		$products_obj = new products();
		$productList = $products_obj->getProductList();
		
		$smarty->assign("placeList", $placeList);
		$smarty->assign("productList", $productList);
		$insertform_productplace_box = $smarty->fetch("productplace/
		productplace_insert_form.html");
		
		$smarty->assign("insertform_productplace_box",$insertform_productplace_box);
		
		$content = $smarty->fetch("productplace/productplace.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function editFormAction(){
		$propla_id 			= $_REQUEST['args'];
		$smarty 			= $_SESSION['smarty'];		
		
		$placesList = array();
		include("model/places.php");
		$places_obj = new places();
		$placesList = $places_obj->getPlaceList();
		
		$productsList = array();
		include("model/products.php");
		$products_obj = new products();
		$productList = $products_obj->getProductList();
		
		$smarty->assign("placesList", $placesList);
		$smarty->assign("productList", $productList);
		
		$productplace_obj 		= new productplace();
		$current_data 			= array();
		$current_data 			= $productplace_obj->getProductPlaceInfo($propla_id);
		
		$smarty->assign("current_data", $current_data);
		
		$editform_productplace_box = $smarty->fetch("productplace/
		productplace_edit_form.html");
		$smarty->assign("editform_productplace_box",$editform_productplace_box);
		
		$content = $smarty->fetch("productplace/productplace.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");	
	}
	
	function editAction()
	{
		$productplace_obj 	= new productplace();
		$data 				= array();
		$data['propla_id'] 			= $_REQUEST['propla_id'];
		$data['propla_pro_id'] 		= $_REQUEST['propla_pro_id'];
		$data['propla_pla_id'] 		= $_REQUEST['propla_pla_id'];
		$data['propla_quantity'] 	= $_REQUEST['propla_quantity'];
		
		$result = $productplace_obj->editAProductPlace($data);
		
		if ($result == 1)
			$msg = "edit successfully";
		else
			$msg = "update failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("productplace/productplace_updateResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
}
?>